<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        h3{
            height: 300px;
        }
    </style>
</head>
<body>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <h3>1</h3>
    <script>
        function throttle(fn,delay){
            var valid = true
            return function(){
                if(!valid){
                    return false
                }
                valid = false
                setTimeout(function(){
                    fn()
                    valid = true
                },delay)
            }
        }

        function getScrollTop(){
            var scrollTop = document.documentElement.scrollTop

            console.log(scrollTop)
        }

        window.addEventListener('scroll',throttle(getScrollTop,500))
    </script>
</body>
</html>